//
//  LoginViewController.m
//  WashForU
//
//  Created by 王俊 on 15/11/24.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "LoginViewController.h"




@implementation LoginViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self customViewSetUp];
    [self customConstrainsAdd];
    [self targetAdd];
}
/*****************添加视图组件********************/
- (void)customViewSetUp
{
    self.titleLabel.text = @"绑定手机登录";
    self.titleLabel.font = [UIFont CustomFont:20];
    
    [self.backButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    _userNameInputField = [[UITextField alloc]init];
    _authCodeInputField = [[UITextField alloc]init];
    _authCodeGetButton  = [[UIButton alloc]init];
    _bindConfirmButton  = [[UIButton alloc]init];
    _descLabel          = [[UILabel alloc]init];
    _descButton         = [[UIButton alloc]init];
    
    [self textFielSetUp:_userNameInputField info:@"请输入手机号码" fontSize:17];
    [self textFielSetUp:_authCodeInputField info:@"请输入验证码" fontSize:17];
    [self buttonSetUp:_authCodeGetButton bgColor:[UIColor GrayColor_188] textColor:[UIColor whiteColor] textInfo:@"获取验证码" fontSize:17];
    [self buttonSetUp:_bindConfirmButton bgColor:[UIColor CustomLightBlue] textColor:[UIColor whiteColor] textInfo:@"绑定手机登录"  fontSize:17];
    [self buttonSetUp:_descButton bgColor:[UIColor clearColor] textColor:[UIColor CustomLightBlue] textInfo:@"《快快洗用户协议》" fontSize:12];
    _descButton.titleLabel.textAlignment = NSTextAlignmentLeft;

    
    _descLabel = [[UILabel alloc]init];
//    _descLabel.text = @"点击\"绑定手机登录\",即表示同意";
//    _descLabel.font = [UIFont CustomFont:12];
//    _descLabel.textAlignment = NSTextAlignmentRight;
    
    [self.descLabel setText:@"点击\"绑定手机登录\",即表示同意" andFont:[UIFont CustomFont:12] andColor:[UIColor blackColor]  andAligm:NSTextAlignmentRight];
    [self.view addSubview:_descLabel];
    
}
/*******************添加约束**********************/
- (void)customConstrainsAdd
{
    [_userNameInputField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.upView.mas_bottom).offset(20);
        make.leading.equalTo(self.view).offset(20);
        make.trailing.equalTo(self.view).offset(-150);
        make.height.mas_equalTo(50);
    }];
    [_authCodeInputField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.leading.equalTo(self.userNameInputField);
        make.trailing.equalTo(self.view).offset(-20);
        make.top.equalTo(self.userNameInputField.mas_bottom).offset(20);
    }];
    [_authCodeGetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.userNameInputField);
        make.trailing.equalTo(self.view).offset(-20);
        make.leading.equalTo(self.userNameInputField.mas_trailing).offset(5);
        make.top.equalTo(self.upView.mas_bottom).offset(20);
    }];
    [_bindConfirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.authCodeInputField.mas_bottom).offset(25);
        make.leading.height.trailing.equalTo(self.authCodeInputField);
    }];
    [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bindConfirmButton.mas_bottom).offset(10);
        make.leading.equalTo(self.bindConfirmButton);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(170);
    }];
    [_descButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(self.descLabel);
        make.width.mas_equalTo(120);
        make.leading.equalTo(self.descLabel.mas_trailing);
    }];
}
/*******************添加事件**********************/
- (void)targetAdd
{
    [_authCodeGetButton addTarget:self action:@selector(authCodeGetButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_descButton addTarget:self action:@selector(descButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_bindConfirmButton addTarget:self action:@selector(bindConfirmButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    
}
/*******************设置Textfield格式**********************/
- (void)textFielSetUp:(UITextField *) textField info:(NSString *) info fontSize:(CGFloat) size
{
    UIView *leftView = [[UIView alloc]init];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(10, 1));
    }];
    leftView.backgroundColor = [UIColor whiteColor];
    textField.placeholder = info;
    textField.font = [UIFont CustomFont:size];
    textField.backgroundColor = [UIColor whiteColor];
    textField.layer.borderWidth = 1;
    textField.layer.borderColor = [UIColor GrayColor_188].CGColor;
    textField.leftView = leftView;
    textField.leftViewMode = UITextFieldViewModeAlways;
    [self.view addSubview:textField];
}
/*********************设置Button格式************************/
- (void)buttonSetUp:(UIButton*) button bgColor:(UIColor *) bgColor textColor:(UIColor *) textColor textInfo:(NSString *) textInfo fontSize:(CGFloat) size
{
    [button setTitle:textInfo forState:UIControlStateNormal];
    [button setBackgroundColor:bgColor];
    [button setTitleColor:textColor forState:UIControlStateNormal];
    [button setTitleColor:bgColor forState:UIControlStateHighlighted];
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    button.titleLabel.font = [UIFont CustomFont:size];
    [self.view addSubview:button];
}
/*******************设置backButton绑定事件********************/
- (void)backButtonClicked
{
    [self.navigationController popViewControllerAnimated:true];
}
- (void)authCodeGetButtonClicked
{
}
- (void)descButtonClicked
{
    
}
- (void)bindConfirmButtonClicked
{
    MainTabBarController *vc = [[MainTabBarController alloc]init];
    [self.navigationController pushViewController:vc animated:true];
}

@end
